/**
 * Copyright (C) 2009-2012, KingHool.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses.
 */
package com.kinghool.smodel.io.source;


import com.kinghool.smodel.ITreeModel;
import com.kinghool.smodel.TreeModel;
import com.kinghool.smodel.def.ModelDefinition;
import com.kinghool.smodel.def.TreeModelDefinition;
import com.kinghool.smodel.io.IModelChannel;
import com.kinghool.smodel.io.IModelSource;

/**
 * 
 * @Author Allen Deng(dengtailin@gmail.com) 
 */
public class TreeModelSource extends BaseModelSource<ITreeModel> implements IModelSource<ITreeModel> {
 
	public TreeModelSource(IModelChannel channel) {
		super(channel);
	}

	public ITreeModel newModelInstance(ModelDefinition modelDefinition) {
		checkModelDefinition(modelDefinition);
		return new TreeModel((TreeModelDefinition) modelDefinition);
	}
	
	protected ModelDefinition getModelDefinition(String id) {
		TreeModelDefinition xmlModelDefinition = TreeModelDefinition.createDefaultTreeModelDefinition(id, null);
		return xmlModelDefinition;
	}
	
	protected void checkModelDefinition(ModelDefinition modelDefinition) {
		if (!(modelDefinition instanceof TreeModelDefinition)) {
			throw new IllegalArgumentException("invalid argument modelDefinition: modelDefinition should be TreeModelDefinition");
		}
	} 	
}
